<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  <style type="text/css">
   tr { background: #CCCCCC; }
   tr:hover { background: #AAABFF; }

   td {
	font-family: Verdana, Arial, Helvetica, sans-serif;
	font-size: 10px;
   }
   .one {
	   background-color: #666666;
	   } 
   .two {
	   background-color: #999999;
	   font-weight:bold; 
	   text-align:center;
	   }
	.s_ip { background-color: #999999; text-align:center; font-weight:bold; }
	.s_name {background-color: #999999; font-weight:bold; }
	.s_location {background-color: #999999; text-align:center; font-weight:bold; }
	.s_contact {background-color: #999999; text-align:center; font-weight:bold; }   
	   
  </style>
<title>simple search</title>
</head>

<body>
<table width="1024" border="0" align="left" cellpadding="1" cellspacing="1">
	<tr>
		<td colspan="5" class="one" align="center">search results</td>
	</tr>
<tr>
    <td class="s_name" width="150">название</td> 
    <td class="s_ip" width="100">ip</td>
    <td class="s_ip" width="100">graphs</td> 
    <td class="s_location">адрес</td> 
    <td class="s_contact">контакт</td>
</tr>


<?php
include("inc.db.conf.php");

$search_query = $_POST["search_query"];

/*
if (!eregi("[[:alpha:]]", $search_query)) {
	echo "Error: you have entered an invalid query, you can only use characters!<br>";
	echo $search_query;
	exit;
	}
*/

$query = "
SELECT
    hosts.hostid, hosts.host, hosts.ip, hosts_profiles.location, hosts_profiles.contact
FROM
    zabbix.hosts INNER JOIN zabbix.hosts_profiles ON (hosts.hostid = hosts_profiles.hostid)
WHERE 		hosts.host LIKE '%$search_query%'
		OR 	hosts.ip LIKE '%$search_query%'
		OR	hosts_profiles.location LIKE '%$search_query%'
		OR 	hosts_profiles.contact LIKE '%$search_query%' 
ORDER BY hosts.host DESC";

$result=mysql_query($query, $link) or die(mysql_errno($link).mysql_error($link));

$rescheck = mysql_num_rows($result);

if ($rescheck == 0){
	echo "Сори, строка поиска ($search_query) не найдена в базе. Попробуйте как-то иначе..";
	exit; 
	}
	else if ($rescheck == 1)
	{
		echo "Найдено <b>1</b> совпадение!<br>";
		}
	else {
		echo "Найдено <b>$rescheck</b> совпадений! <br>";
		}

while ($row = mysql_fetch_array($result)) {
	$zbxhostid= $row["hostid"];
	$zbxip= $row["ip"];
	$zbxhost = $row["host"];
	$zbxlocation = $row["location"];
	$zbxcontact = $row["contact"];
?>
    <tr>
    	<td><a href="last20events.php?hostid=<?php echo $zbxhostid ?>" title="Последние 20 событий узла <?php echo $zbxhost ?>"><?php echo $zbxhost ?></a></td>
    	<td align="center"><?php echo $zbxip ?></td>
        	<td>	график avail<br> 	<!-- http://zabbix.telsycom.local/history.php?action=showgraph&itemid=27788 -->
            		график delay<br> 	<!-- http://zabbix.telsycom.local/history.php?action=showgraph&itemid=27790 -->
                    график loss			<!-- http://zabbix.telsycom.local/history.php?action=showgraph&itemid=27789 -->
            </td>
    	<td><?php echo $zbxlocation ?></td>
    	<td><?php echo $zbxcontact ?></td>
    </tr>

<?php } ?>

	<tr>
		<td colspan="6" class="one" align="right">
    	<a href="zbx-frontend.html" title="back" target="_self"><b>Back</b></a>
    	</td>
	</tr>
</table>
</body>
</html>
